package com.wc.creative.Q357;

import java.util.Scanner;

/**
 * @Author congege
 * @Description
 * 沈老师的岛
 * https://acm.creative3605.com/problems/357
 * @Date Created in 2023/12/23-22:11
 */
public class Main {
    static int[] positionX = new int[]{0, 1, 0, -1, 1, -1, 1, -1};
    static int[] positionY = new int[]{1, 0, -1, 0, -1, 1, 1, -1};
    static char[][] map;
    static int n, m;
    static int ans;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            ans = 0;
            n = sc.nextInt();
            m = sc.nextInt();
            map = new char[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = sc.next().toCharArray();
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (map[i][j] == '@') {
                        ans++;
                        dfs(i,j);
                    }
                }
            }
            System.out.println(ans);
        }
    }

    public static void dfs(int x, int y) {
        map[x][y] = '*';
        for (int i = 0; i < 8; i++) {
            int nx = x + positionX[i];
            int ny = y + positionY[i];
            if (!isBorder(nx, ny) && map[nx][ny] == '@') {
                dfs(nx, ny);
            }
        }
    }

    public static boolean isBorder(int x, int y) {
        return x < 0 || x == n || y < 0 || y == m;
    }
}

